package com.hyb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hyb.entity.Record;
import com.hyb.mapper.RecordMapper;
import com.hyb.page.PageReq;
import com.hyb.service.RecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  交往记录Service接口实现类
 * </p>
 *
 * @author hyb
 * @since 2021-12-29
 */
@Service
public class RecordServiceImpl extends ServiceImpl<RecordMapper, Record> implements RecordService {

    @Autowired
    private RecordMapper recordMapper;
    @Override
    public void createRecord(Record record) {
        recordMapper.insert(record);
    }

    @Override
    public PageReq getRecords(Integer limit, Integer current, Integer customerId) {
        Page<Record> page = new Page<>(current,limit);
        QueryWrapper<Record> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("customer_id",customerId);
        Page<Record> page1 = recordMapper.selectPage(page, queryWrapper);
        PageReq pageReq = new PageReq();
        pageReq.setTotal(page1.getTotal());
        pageReq.setMyData(page1.getRecords());
        return pageReq;
    }

    @Override
    public Record getRecordByRecordId(Integer recordId) {
        QueryWrapper<Record> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("record_id",recordId);
        return recordMapper.selectOne(queryWrapper);
    }

    @Override
    public void updateRecord(Record record) {
        recordMapper.updateById(record);
    }

    @Override
    public void deleteRecordById(Integer recordId) {
        recordMapper.deleteById(recordId);
    }
}
